import { PublicEventService } from './../../public-event.service';
import { Router } from '@angular/router';
import { Component, OnInit, Input, ComponentRef } from '@angular/core';
import { FundInfoChangeService } from './fundInfo-change.service';
import * as _ from 'lodash';
import { environment } from '../../../../../environments/environment';
import { FileUploader } from "ng2-file-upload";
import * as moment from 'moment';
import { Util } from 'app/common/util';
import { DataService } from '../../../../services/data.service';

@Component({
  selector: 'app-fundInfo-change',
  templateUrl: './fundInfo-change.component.html',
  styleUrls: ['./fundInfo-change.component.scss'],
  providers: [FundInfoChangeService]
})
export class FundInfoChangeComponent implements OnInit {
  //其他费率字节长度
  public realLength: any;
  // 产品基础信息
  public fundInfoBasic: any;
  // 产品改造类型： bgzc-变更注册、 yqmj-延期募集、tzfl-调整费率、zsfe-增设份额、qtbg-其他变更
  public type: any;

  // lodash
  public _: any = _;
  // dataTable
  public dataTable: any =
  window['$']('#list_table').DataTable({
    "paging": false,
    "lengthChange": false,
    "searching": false,
    "ordering": true,
    "info": false,
    "destroy": true,
    "columnDefs": [
      { "orderable": false, "targets": 0 }
    ],
    "order": [
      [0, null]
    ],
  });
  //查询原变更注册界面判断是否显示产品改造信息
  public bgzcStatu: any;
  public yqmjStatu: any;
  public tzflStatu: any;
  public zsfeStatu: any;
  public qtbgStatu: any;
  // 菜单数据
  public menuData: any;
  // 菜单权限set
  public menuResourceSet: any = [];
  // 用于保存显示的附件列表
  public activeFileList = [];
  // 用于保存激活的文件tab大类
  public activeFileType = "";
  // 用于控制变更注册后才能上传文件(默认为1，可以上传)
  public bgzcFileStatus: any = 1;
  // 用于禁用变更注册后保存按钮(默认为false,可以保存)
  public bgzcSaveButton: any = false;
  // 附件树内码
  public nFileFundNo: any;
  // 基础文件数据  GM=公募
  public jcwjGMDataList = [];
  // 审批文件数据
  public spwjGMDataList = [];
  // 产品改造文件数据
  public cpgzGMDataList = [];
  // 其他文件数据
  public qtwjGMDataList = [];
  // 历史附件数据
  public historyGMDataList = [];
  // 基础文件
  public jcwjGM: any;
  // 审批文件
  public spwjGM: any;
  // 产品改造文件
  public cpgzwjGM: any;
  // 其他文件
  public qtwjGM: any;
  // 历史附件
  public historyGM: any;
  // 初始化定义uploader变量,用来配置input中的uploader属性
  public uploader: FileUploader = new FileUploader({});
  // 上传文件的名称
  public uploadFileName: any = "";
  // 产品上传参数
  public sCreatorNo: any;
  public sCreator: any;
  public sAttachCode: any;
  public nFundNo: any;
  public nAttachNo: any;
  public sAttachType: any;
  public parentCode: any;
  public parentType: any;
  public sFundType: any;
  // 选择文件状态
  public fileStatus = false;
  // 附件历史数据
  public fileHistoryData: any;

  public listData: any = {};
  product: any = {};
  // 产品基本信息
  public baseInfo: any = {};

  // 产品审核信息
  public checkInfo: any = {};

  //产品改造进度列表
  public scheduleList = {};

  //托管行字典值
  // public bankDictionaryList = [];
  /**
   * 产品改造变更注册
   * data等于true允许产品改造
   */
  public reformStatus = false;
  /**
   * 产品改造延期募集
   * data等于true允许产品改造
   */
  public yqmjStatus = false;
  /**
  * 产品改造调整费率
  * data等于true允许产品改造
  */
  public tzflStatus = false;
  /**
  * 产品改造增设份额
  * data等于true允许产品改造
  */
  public zsfeStatus = false;
  /**
  * 产品改造其他变更
  * data等于true允许产品改造
  */
  public qtbgStatus = false;

  // 列表是否全选
  public isCheckedAll = false;

  // 该变量用于已获批、已发行页面显示变更注册按钮
  public showChangeBtn: any

  // 该变量用于控制是否显示创设新产品按钮
  public showNewBtn: any;

  // 根据产品改造单选按钮显示相应输入框的变量
  public isShowProdInput: any;

  // 根据产品改造-变更注册-是否召开持有人大会显示持有人大会公告时间、持有人大会决议生效时间
  public isShowCyrdh: any;
  //获取单个产品基础信息post
  public singleProductPost = {
    nFundNo: ""
  }

  /**
   * 查询单个审核信息post
   */
  public singleCheckPost = {
    nFundNo: ''
  }
  //分页列表post数据
  public postBody = {
    pageIndex: 1,
    pageSize: 10,
    sFundStatus: '',
    sFullName: '',
    sFundCode: '',
    sIsRegisterChg: ''
  };
  public dictionaryList = {
    FUND_CATEGORY_GM: [],
    INVEST_STYLE: [],
    EXCHANGE: []
  };
  // 基金经理
  public managerList = [];
  // 原变更注册基金经理多选下拉框
  public managerSelectList = [];
  // 原变更注册基金经理多选下拉框
  public oldManagerSelectList = [];
  // 变更注册原创建日期
  public bgzcCreateDate: any;
  // 变更注册日期（只用于显示）
  public ngzcCreateDate: any;
  // 备案机构、受托人、托管人
  public distionary: any = {
    RECORDORG_TYPE: [],  // 备案机构
    LINK_PRINCIPAL_NO: [],   //受托人
    TRUSTEE: []   //  托管人
  }
  //变更注册绑定数据
  public bgzcInfo = {
    productTransformation: {

      sFundName: "",
      sFundCode: "",
      sChangeType: "bgzc",
      dBh: '',
      dPf: ''
    },
    publicissueBasicInfo: {
      sFundCode: "",
      sFundName: "",
      sFullName: "",
      sFundType: '1',
      sFundCategory: "",
      sIsQdii: '0',
      sInvestStyle: "",
      sPmAccount: "",
      sPmName: "",
      sListType: "",
      sExchange: "",
      sBank: '',
      dBankConfirm: "",
      sInvestScope: "",
      sBenchmark: "",
      sManagementFee: "",
      sTrusteeFee: "",
      sOtherFee: "",
      dIssue: "",
      dEstablishment: "",
      sCreator: "",
      sCreatorNo: "",
      sIsRegisterChg: "",
      nRegisterChgNo: "",
      sStatus: "",
      sSubStatus: "",
      sSubStatusSet: "",
      sStatusRunning: "",
      sRemark: ""
    }
  };
  /**
   * 延期募集、调整费率、增设份额、其他变更绑定数据
   */
  public yqmjPostBody = {
    publicissueExamineInfo: {
      sRemarkChg: "",
      sZshRemarkChg: "",
      nFundNo: "",
      sFundCode: "",
      sFundName: "",
      sFullName: "",
      sFundType: "",
      nAuditNo: '',
      dLxCommittee: "",
      dAuditCommittee: "",
      dCsrsSb: "",
      dCsrsBz: "",
      dCsrsSl: "",
      dCsrsFeedback: "",
      dCsrsCommitopt: "",
      dCsrsReply: "",
      dCsrsReplyEnd: "",
      dCsrsAnswer: "",
      sPossessorMt: "",
      dPossessorGg: "",
      dPossessorJy: "",
      dRaisePostponeBh: "",
      dRaisePostponePf: "",
      dRaisePostponeHh: "",
      dRatePossessorMt: "",
      dRatePossessorGg: "",
      dRatePossessorJy: "",
      dChgRecordSb: "",
      dChgSb: "",
      dOtherchgRecordSb: "",
      dOtherChgGg: ""
    },
    productTransformation: {
      nFundNo: "",
      sFundName: "",
      sFundCode: "",
      sFullName: "",
      sChangeType: "",
      dBh: '',
      dPf: ''
    },
    publicissueBasicInfo: {
      nFundNo: "",
      sFundCode: "",
      sFundName: "",
      sFullName: "",
      sFundType: "",
      sFundCategory: "",
      sIsQdii: "",
      sInvestStyle: "",
      sPmAccount: "",
      sPmName: "",
      sListType: "",
      sExchange: "",
      sBank: "",
      dBankConfirm: "",
      sInvestScope: "",
      sBenchmark: "",
      sManagementFee: '',
      sTrusteeFee: '',
      sOtherFee: "",
      dIssue: "",
      dEstablishment: "",
      sCreator: "",
      sCreatorNo: "",
      sIsRegisterChg: "",
      nRegisterChgNo: "",
      sStatus: "",
      sSubStatus: "",
      sSubStatusSet: "",
      sStatusRunning: "",
      sRemark: ""
    }

  };
  //基础信息绑定数据
  public baseInfoPost = {
    sFundCode: '',
    sFundName: '',
    sFullName: '',
    sFundType: '1',
    sFundCategory: '',
    sIsQdii: '',
    sInvestStyle: '',
    sPmAccount: '',
    sPmName: '',
    sListType: '0',
    sExchange: '',
    sBank: '',
    dBankConfirm: '',
    sInvestScope: '',
    sBenchmark: '',
    sManagementFee: '',
    sTrusteeFee: '',
    sOtherFee: '',
    dIssue: '',
    dEstablishment: '',
    sCreator: '',
    sCreatorNo: '',
    sIsRegisterChg: '',
    nRegisterChgNo: '',
    sStatus: '',
    sStatusRunning: '1',
    sRemark: '',
    dCreateTime: ''
  };
  /**
   * 产品改造延期募集、调整费率、增设份额、其他变更通用postBody
   */
  public auditInfoPostBody = {
    productTransformation: {
      nFundNo: 624,
      sFundName: "基金005",
      sChangeType: "yqmj",
      sChangeTypeValue: "延期募集"
    },
    publicissueExamineInfo: {
      nFundNo: 624,
      dLxCommittee: "2017-11-08"
    }
  }

  constructor(
    public fundInfoChangeService: FundInfoChangeService,
    public router: Router,
    public publicEventService: PublicEventService,
    public dataService: DataService
  ) {
    // 解决附件跨域问题
    this.uploader.onAfterAddingFile = (file) => { file.withCredentials = false; };
  }

  ngOnInit() {
    // 初始化select2多选下拉框
    window['$'](".select2").select2();
    // 字典值
    this.dictionaryList = JSON.parse(localStorage.getItem("dictionaryList"));
    // 托管行
    // this.bankDictionaryList = JSON.parse(localStorage.getItem("bankDictionaryList"));
    // 基金经理
    this.getManagerList();

    this.initPageInfo(this.fundInfoBasic, this.type);

    this.getDictionary();
  }


  /**
   * 初始化页面信息
   * @param fundInfoBasic 产品基础信息
   * @param type 产品改造类型： bgzc-变更注册、 yqmj-延期募集、tzfl-调整费率、zsfe-增设份额、qtbg-其他变更
   */
  initPageInfo(fundInfoBasic, type) {
    var that = this;
    this.managerSelectList = [];
    // 根据产品改造类型显示产品改造页面
    this.isShowProdInput = type;

    // 基金经理
    if (fundInfoBasic && fundInfoBasic.sPmNames) {
      this.managerSelectList = _.concat([], fundInfoBasic.sPmNames);
    }

    // 初始化数据
    if (_.includes(["yqmj", "tzfl", "zsfe", "qtbg"], type)) { // 非变更注册类型
      this.yqmjPostBody.productTransformation.nFundNo = fundInfoBasic.nFundNo;
      this.yqmjPostBody.productTransformation.sFundName = fundInfoBasic.sFundName;
      this.yqmjPostBody.productTransformation.sFullName = fundInfoBasic.sFullName;
      this.yqmjPostBody.publicissueExamineInfo.sFundName = fundInfoBasic.sFundName;
      this.yqmjPostBody.publicissueExamineInfo.sFundCode = fundInfoBasic.sFundCode;
      this.yqmjPostBody.publicissueExamineInfo.sFundType = fundInfoBasic.sFundType;
      this.yqmjPostBody.publicissueExamineInfo.sFullName = fundInfoBasic.sFullName;
      this.yqmjPostBody.publicissueBasicInfo.nFundNo = fundInfoBasic.nFundNo;
      this.yqmjPostBody.publicissueBasicInfo.sFundName = fundInfoBasic.sFundName;
      this.yqmjPostBody.publicissueBasicInfo.sFundCode = fundInfoBasic.sFundCode;
      this.yqmjPostBody.publicissueBasicInfo.sFundType = fundInfoBasic.sFundType;
      this.yqmjPostBody.publicissueBasicInfo.sFullName = fundInfoBasic.sFullName;
      this.yqmjPostBody.publicissueBasicInfo.sFundCategory = fundInfoBasic.sFundCategory;
      this.yqmjPostBody.publicissueBasicInfo.sIsQdii = fundInfoBasic.sIsQdii;
      this.yqmjPostBody.publicissueBasicInfo.sInvestStyle = fundInfoBasic.sInvestStyle;
      this.yqmjPostBody.publicissueBasicInfo.sPmAccount = fundInfoBasic.sPmAccount;
      this.yqmjPostBody.publicissueBasicInfo.sPmName = fundInfoBasic.sPmName;
      this.yqmjPostBody.publicissueBasicInfo.sListType = fundInfoBasic.sListType;
      this.yqmjPostBody.publicissueBasicInfo.sExchange = fundInfoBasic.sExchange;
      this.yqmjPostBody.publicissueBasicInfo.sBank = fundInfoBasic.sBank;
      this.yqmjPostBody.publicissueBasicInfo.dBankConfirm = fundInfoBasic.dBankConfirm;
      this.yqmjPostBody.publicissueBasicInfo.sInvestScope = fundInfoBasic.sInvestScope;
      this.yqmjPostBody.publicissueBasicInfo.sBenchmark = fundInfoBasic.sBenchmark;
      this.yqmjPostBody.publicissueBasicInfo.sManagementFee = fundInfoBasic.sManagementFee;
      this.yqmjPostBody.publicissueBasicInfo.sTrusteeFee = fundInfoBasic.sTrusteeFee;
      this.yqmjPostBody.publicissueBasicInfo.sOtherFee = fundInfoBasic.sOtherFee;
      this.yqmjPostBody.publicissueBasicInfo.dIssue = fundInfoBasic.dIssue;
      this.yqmjPostBody.publicissueBasicInfo.dEstablishment = fundInfoBasic.dEstablishment;
      this.yqmjPostBody.publicissueBasicInfo.sCreator = fundInfoBasic.sCreator;
      this.yqmjPostBody.publicissueBasicInfo.sCreatorNo = fundInfoBasic.sCreatorNo;
      this.yqmjPostBody.publicissueBasicInfo.sIsRegisterChg = fundInfoBasic.sIsRegisterChg;
      this.yqmjPostBody.publicissueBasicInfo.nRegisterChgNo = fundInfoBasic.nRegisterChgNo;
      this.yqmjPostBody.publicissueBasicInfo.sStatus = fundInfoBasic.sStatus;
      this.yqmjPostBody.publicissueBasicInfo.sStatusRunning = fundInfoBasic.sStatusRunning;
      this.yqmjPostBody.publicissueBasicInfo.sSubStatus = fundInfoBasic.sSubStatus;
      this.yqmjPostBody.publicissueBasicInfo.sSubStatusSet = fundInfoBasic.sSubStatusSet;
      this.yqmjPostBody.publicissueBasicInfo.sRemark = fundInfoBasic.sRemark;
      this.yqmjPostBody.productTransformation.sFundCode = fundInfoBasic.sFundCode;

      // 附件关联的产品内部编码
      this.nFileFundNo = fundInfoBasic.nFundNo;
      // 加载附件树
      this.loadFileTree();

    } else if (type == "bgzc") { // 变更注册
      this.bgzcInfo.productTransformation.sFundName = fundInfoBasic.sFundName;
      this.bgzcInfo.productTransformation.sFundCode = fundInfoBasic.sFundCode;
      this.bgzcInfo.publicissueBasicInfo.sFundName = fundInfoBasic.sFundName;
      this.bgzcInfo.publicissueBasicInfo.sFundCode = fundInfoBasic.sFundCode;
      this.bgzcInfo.publicissueBasicInfo.sFundType = fundInfoBasic.sFundType;
      this.bgzcInfo.publicissueBasicInfo.sFullName = fundInfoBasic.sFullName;
      this.bgzcInfo.publicissueBasicInfo.sFundCategory = fundInfoBasic.sFundCategory;
      this.bgzcInfo.publicissueBasicInfo.sIsQdii = fundInfoBasic.sIsQdii;
      this.bgzcInfo.publicissueBasicInfo.sInvestStyle = fundInfoBasic.sInvestStyle;
      this.bgzcInfo.publicissueBasicInfo.sPmAccount = fundInfoBasic.sPmAccount;
      this.bgzcInfo.publicissueBasicInfo.sPmName = fundInfoBasic.sPmName;
      this.bgzcInfo.publicissueBasicInfo.sListType = fundInfoBasic.sListType;
      this.bgzcInfo.publicissueBasicInfo.sExchange = fundInfoBasic.sExchange;
      this.bgzcInfo.publicissueBasicInfo.sBank = fundInfoBasic.sBank;
      this.bgzcInfo.publicissueBasicInfo.dBankConfirm = fundInfoBasic.dBankConfirm;
      this.bgzcInfo.publicissueBasicInfo.sInvestScope = fundInfoBasic.sInvestScope;
      this.bgzcInfo.publicissueBasicInfo.sBenchmark = fundInfoBasic.sBenchmark;
      this.bgzcInfo.publicissueBasicInfo.sManagementFee = fundInfoBasic.sManagementFee;
      this.bgzcInfo.publicissueBasicInfo.sTrusteeFee = fundInfoBasic.sTrusteeFee;
      this.bgzcInfo.publicissueBasicInfo.sOtherFee = fundInfoBasic.sOtherFee;
      this.bgzcInfo.publicissueBasicInfo.dIssue = fundInfoBasic.dIssue;
      this.bgzcInfo.publicissueBasicInfo.dEstablishment = fundInfoBasic.dEstablishment;
      this.bgzcInfo.publicissueBasicInfo.sCreator = fundInfoBasic.sCreator;
      this.bgzcInfo.publicissueBasicInfo.sCreatorNo = fundInfoBasic.sCreatorNo;
      this.bgzcInfo.publicissueBasicInfo.sIsRegisterChg = fundInfoBasic.sIsRegisterChg;
      //将旧产品代码赋予变更注册将要新建的新产品里面的原变更注册基金内码
      this.bgzcInfo.publicissueBasicInfo.nRegisterChgNo = fundInfoBasic.nFundNo;
      this.bgzcInfo.publicissueBasicInfo.sStatus = fundInfoBasic.sStatus;
      this.bgzcInfo.publicissueBasicInfo.sStatusRunning = fundInfoBasic.sStatusRunning;
      this.bgzcInfo.publicissueBasicInfo.sRemark = fundInfoBasic.sRemark;
      this.ngzcCreateDate = fundInfoBasic.dCreateTime;

      // 用于控制变更注册后才能上传文件
      this.bgzcFileStatus = 0;
      // 用于禁用变更注册后后保存按钮
      this.bgzcSaveButton = false;
    }

    //获取单个审核信息
    this.getSingleCheckInfo(fundInfoBasic.nFundNo);
    
  }


  //判断是否变更注册
  isRegistrationChange(item, type) {
    var that = this;
    let getBody = {
      nFundNo: item,
      sChangeType: type
    }
    this.fundInfoChangeService.isRegistrationChange(getBody).subscribe(data => {
      if (data) {
        switch (type) {
          case 'bgzc':
            that.reformStatus = data;
            break;
          case 'yqmj':
            that.yqmjStatus = data;
            break;
          case 'tzfl':
            that.tzflStatus = data;
            break;
          case 'zsfe':
            that.zsfeStatus = data;
            break;
          case 'qtbg':
            that.qtbgStatus = data;
            break;
        }
      }
    });
  }

  //保存 变更注册
  editRegistrationChange() {
    let that = this;
    this.bgzcInfo.publicissueBasicInfo.sPmAccount = this.ctrlManagerId();
    this.bgzcInfo.publicissueBasicInfo.sPmName = this.ctrlManagerName();
    this.bgzcInfo.publicissueBasicInfo.sIsRegisterChg = '1';
    console.log(this.bgzcInfo)
    if (this.requireAdd()) {
      // if (this.beforeTime()) {
        window["swal"]({
          title: "提示！",
          text: "是否确定进行变更注册",
          type: "warning",
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          showCancelButton: true,
          closeOnConfirm: false,
          closeOnCancel: true,
          showLoaderOnConfirm: true
        },
          function (isConfirm) {
            if (isConfirm) {
              that.fundInfoChangeService.editRegistrationChange(that.bgzcInfo).subscribe(data => {
                if (data) {
                  // RE
                  // that.loadlist();
                  // that.router.navigate(['/pages/publicofferingList/fashjjlx']);
                  window['swal']("提示", "变更注册成功", "success");
                  // 变更注册后新产品内码
                  that.nFileFundNo = data.publicissueBasicInfo.nFundNo;
                  // 变更注册后文件上传到新产品
                  that.bgzcFileStatus = 1;
                  //  变更注册后禁用保存按钮
                  that.bgzcSaveButton = true;

                  //   发射事件 刷新Yhp模块列表数据
                  that.publicEventService.eventEmit.emit("RefreshYhpList");

                  //   发射事件 刷新yfx模块列表数据
                  that.publicEventService.eventEmit.emit("RefreshYfxList");
                  window['$']("#fundInfoChageModal").modal('hide');
                }
              })
            }
          })
      // } else {
      //   window['swal']("提示", "发行日期不能比成立日期早", "warning");
      // }
    }
  }

  //保存 延期募集、调整费率、增设份额、其他变更
  delayCollect(item) {
    let that = this;
    this.yqmjPostBody.productTransformation.sChangeType = item;
    var changeTypeName = '';
    if (item == 'yqmj') {
      this.yqmjPostBody.productTransformation.dBh = this.yqmjPostBody.publicissueExamineInfo.dRaisePostponeBh;
      this.yqmjPostBody.productTransformation.dPf = this.yqmjPostBody.publicissueExamineInfo.dRaisePostponeHh;
      changeTypeName = '延期募集';
    } else if (item == 'tzfl') {
      this.yqmjPostBody.productTransformation.dBh = this.yqmjPostBody.publicissueExamineInfo.dRatePossessorMt;
      this.yqmjPostBody.productTransformation.dPf = this.yqmjPostBody.publicissueExamineInfo.dRatePossessorJy;
      changeTypeName = '调整费率';
    } else if (item == 'zsfe') {
      this.yqmjPostBody.productTransformation.dBh = this.yqmjPostBody.publicissueExamineInfo.dChgRecordSb;
      this.yqmjPostBody.productTransformation.dPf = this.yqmjPostBody.publicissueExamineInfo.dChgSb;
      changeTypeName = '增设份额';
    } else if (item == 'qtbg') {
      this.yqmjPostBody.productTransformation.dBh = this.yqmjPostBody.publicissueExamineInfo.dOtherchgRecordSb;
      this.yqmjPostBody.productTransformation.dPf = this.yqmjPostBody.publicissueExamineInfo.dOtherChgGg;
      changeTypeName = '其他变更';
    }

    window["swal"]({
      title: "提示！",
      text: "是否确定进行 " + changeTypeName + " 产品改造",
      type: "warning",
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      showCancelButton: true,
      closeOnConfirm: false,
      closeOnCancel: true,
      showLoaderOnConfirm: true
    },
      function (isConfirm) {
        if (isConfirm) {
          that.fundInfoChangeService.delayCollect(that.yqmjPostBody).subscribe(data => {
            if (data) {
              that.dataService.productChangeGM.emit('产品变更');
              window['$']("#fundInfoChageModal").modal('hide');
              window['swal']("提示", changeTypeName + "产品改造成功", "success");
            }
          })
        }
      })
  }

  //查询单个产品审核信息
  getSingleCheckInfo(item) {
    let that = this;
    this.singleCheckPost.nFundNo = item;
    this.bgzcStatu = '';
    this.yqmjStatu = '';
    this.tzflStatu = '';
    this.zsfeStatu = '';
    this.qtbgStatu = '';
    this.yqmjPostBody.publicissueExamineInfo.nFundNo = "";
    this.yqmjPostBody.publicissueExamineInfo.nAuditNo = "";
    this.yqmjPostBody.publicissueExamineInfo.dLxCommittee = "";
    this.yqmjPostBody.publicissueExamineInfo.dAuditCommittee = "";
    this.yqmjPostBody.publicissueExamineInfo.dCsrsSb = "";
    this.yqmjPostBody.publicissueExamineInfo.dCsrsBz = "";
    this.yqmjPostBody.publicissueExamineInfo.dCsrsSl = "";
    this.yqmjPostBody.publicissueExamineInfo.dCsrsFeedback = "";
    this.yqmjPostBody.publicissueExamineInfo.dCsrsCommitopt = "";
    this.yqmjPostBody.publicissueExamineInfo.dCsrsReply = "";
    this.yqmjPostBody.publicissueExamineInfo.dCsrsReplyEnd = "";
    this.yqmjPostBody.publicissueExamineInfo.dCsrsAnswer = "";
    this.yqmjPostBody.publicissueExamineInfo.sPossessorMt = "";
    this.yqmjPostBody.publicissueExamineInfo.dPossessorGg = "";
    this.yqmjPostBody.publicissueExamineInfo.dPossessorJy = "";
    this.yqmjPostBody.publicissueExamineInfo.dRaisePostponeBh = "";
    this.yqmjPostBody.publicissueExamineInfo.dRaisePostponePf = "";
    this.yqmjPostBody.publicissueExamineInfo.dRaisePostponeHh = "";
    this.yqmjPostBody.publicissueExamineInfo.dRatePossessorMt = "";
    this.yqmjPostBody.publicissueExamineInfo.dRatePossessorGg = "";
    this.yqmjPostBody.publicissueExamineInfo.dRatePossessorJy = "";
    this.yqmjPostBody.publicissueExamineInfo.dChgRecordSb = "";
    this.yqmjPostBody.publicissueExamineInfo.dChgSb = "";
    this.yqmjPostBody.publicissueExamineInfo.dOtherChgGg = "";
    this.yqmjPostBody.publicissueExamineInfo.sRemarkChg = "";
    this.yqmjPostBody.publicissueExamineInfo.sZshRemarkChg = "";
    this.fundInfoChangeService.getSingleCheckInfo(this.singleCheckPost).subscribe(data => {
      if (data.publicissueExamineInfo !== null) {
        //将获取到的数据赋予baseInfoPost对象
        //查询到的审核信息
        this.yqmjPostBody.publicissueExamineInfo.nFundNo = data.publicissueExamineInfo.nFundNo;
        this.yqmjPostBody.publicissueExamineInfo.nAuditNo = data.publicissueExamineInfo.nAuditNo;
        this.yqmjPostBody.publicissueExamineInfo.dLxCommittee = data.publicissueExamineInfo.dLxCommittee;
        this.yqmjPostBody.publicissueExamineInfo.dAuditCommittee = data.publicissueExamineInfo.dAuditCommittee;
        this.yqmjPostBody.publicissueExamineInfo.dCsrsSb = data.publicissueExamineInfo.dCsrsSb;
        this.yqmjPostBody.publicissueExamineInfo.dCsrsBz = data.publicissueExamineInfo.dCsrsBz;
        this.yqmjPostBody.publicissueExamineInfo.dCsrsSl = data.publicissueExamineInfo.dCsrsSl;
        this.yqmjPostBody.publicissueExamineInfo.dCsrsFeedback = data.publicissueExamineInfo.dCsrsFeedback;
        this.yqmjPostBody.publicissueExamineInfo.dCsrsCommitopt = data.publicissueExamineInfo.dCsrsCommitopt;
        this.yqmjPostBody.publicissueExamineInfo.dCsrsReply = data.publicissueExamineInfo.dCsrsReply;
        this.yqmjPostBody.publicissueExamineInfo.dCsrsReplyEnd = data.publicissueExamineInfo.dCsrsReplyEnd;
        this.yqmjPostBody.publicissueExamineInfo.dCsrsAnswer = data.publicissueExamineInfo.dCsrsAnswer;
        this.yqmjPostBody.publicissueExamineInfo.sPossessorMt = data.publicissueExamineInfo.sPossessorMt;
        this.yqmjPostBody.publicissueExamineInfo.dPossessorGg = data.publicissueExamineInfo.dPossessorGg;
        this.yqmjPostBody.publicissueExamineInfo.dPossessorJy = data.publicissueExamineInfo.dPossessorJy;
        this.yqmjPostBody.publicissueExamineInfo.dRaisePostponeBh = data.publicissueExamineInfo.dRaisePostponeBh;
        this.yqmjPostBody.publicissueExamineInfo.dRaisePostponePf = data.publicissueExamineInfo.dRaisePostponePf;
        this.yqmjPostBody.publicissueExamineInfo.dRaisePostponeHh = data.publicissueExamineInfo.dRaisePostponeHh;
        this.yqmjPostBody.publicissueExamineInfo.dRatePossessorMt = data.publicissueExamineInfo.dRatePossessorMt;
        this.yqmjPostBody.publicissueExamineInfo.dRatePossessorGg = data.publicissueExamineInfo.dRatePossessorGg;
        this.yqmjPostBody.publicissueExamineInfo.dRatePossessorJy = data.publicissueExamineInfo.dRatePossessorJy;
        this.yqmjPostBody.publicissueExamineInfo.dChgRecordSb = data.publicissueExamineInfo.dChgRecordSb;
        this.yqmjPostBody.publicissueExamineInfo.dChgSb = data.publicissueExamineInfo.dChgSb;
        this.yqmjPostBody.publicissueExamineInfo.dOtherChgGg = data.publicissueExamineInfo.dOtherChgGg;
        this.yqmjPostBody.publicissueExamineInfo.dOtherchgRecordSb = data.publicissueExamineInfo.dOtherchgRecordSb;
        this.yqmjPostBody.publicissueExamineInfo.sRemarkChg = data.publicissueExamineInfo.sRemarkChg;
        this.yqmjPostBody.publicissueExamineInfo.sZshRemarkChg = data.publicissueExamineInfo.sZshRemarkChg;
        this.bgzcStatu = data.bgzc;
        this.yqmjStatu = data.yqmj;
        this.tzflStatu = data.tzfl;
        this.zsfeStatu = data.zsfe;
        this.qtbgStatu = data.qtbg;

        setTimeout(function () {
          // 初始化select2多选下拉框
          window['$'](".select2").select2();
          window['$']('#sTrusteeSelected').select2({ width: '184px', tags: true });
          window['$']('#sTrusteeSelected').on("select2:select", function (e) {
            that.bgzcInfo.publicissueBasicInfo.sBank = window['$']('#sTrusteeSelected').select2("val");
          })
          //基金运作方式
          window['$']('#sInvestStyleSelected').select2({ width: '184px', tags: true });
          window['$']('#sInvestStyleSelected').on("select2:select", function (e) {
            that.bgzcInfo.publicissueBasicInfo.sInvestStyle = window['$']('#sInvestStyleSelected').select2("val");
          })
        }, 1);
      }
    })
  }

  // 获取产品树
  loadFileTree() {
    let that = this;
    //  如果是变更注册，加载空附件树
    if (this.bgzcFileStatus == 0) {
      this.nFileFundNo = "";
    }

    let getBody = {
      "sFundType": 1,
      "nFundNo": this.nFileFundNo
    }
    this.fundInfoChangeService.getFileTree(getBody).subscribe((data) => {
      if (data) {
        // 重置附件变量
        that.activeFileList = [];
        that.jcwjGMDataList = [];
        that.spwjGMDataList = [];
        that.cpgzGMDataList = [];
        that.qtwjGMDataList = [];
        that.historyGMDataList = [];
        _.forEach(data.subTree, function (item, index) {
          that.activeFileList.push(item.sAttachCode);
          switch (item.sAttachCode) {
            case "jcwjGM":
              that.jcwjGM = item.subTree;
              let _jcwjGMDataList = [];
              _.forEach(that.jcwjGM, function (ite) {          // ite是附件小分类
                _.forEach(ite.fileList, function (it) {         // it是附件
                  it.sFundType = ite.sFundType;                 // 附件类型 2
                  it["sParentType"] = item.sAttachType;         // 附件大分类名称 产品方案
                  it["sParentCode"] = ite.sParentCode;          // 附件大分类编码 cpfaYDD
                  it["parentType"] = ite.sAttachType;           // 附件小分类名称 产品需求表
                  it["attachCode"] = ite.sAttachCode;           // 附件小分类编码 cpxqbYDD
                  it["subNodeL"] = ite.fileList.length;         // 附件小分类长度
                  it["sType"] = "";                             // 附件小分类名称
                  it["editStatus"] = "0";                       // 附件名编辑状态
                  it["fileName"] = "";                          // 附件修改名称
                  it["fileType"] = "";                          // 附件后缀
                  _jcwjGMDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;     // 附件小分类名称
              });
              that.jcwjGMDataList = _jcwjGMDataList;
              break;
            case "spwjGM":
              that.spwjGM = item.subTree;
              let _spwjGMDataList = [];
              _.forEach(that.spwjGM, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = "";
                  _spwjGMDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.spwjGMDataList = _spwjGMDataList;
              break;
            case "cpgzwjGM":
              that.cpgzwjGM = item.subTree;
              let _cpgzGMDataList = [];
              _.forEach(that.cpgzwjGM, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = "";
                  _cpgzGMDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              that.cpgzGMDataList = _cpgzGMDataList;
              break;
            case "qtwjGM":
              that.qtwjGM = item.subTree;
              _.forEach(that.qtwjGM, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = "";
                  that.qtwjGMDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              break;
            case "historyGM":
              that.historyGM = item.subTree;
              _.forEach(that.historyGM, function (ite) {
                _.forEach(ite.fileList, function (it) {
                  it.sFundType = ite.sFundType;
                  it["sParentType"] = item.sAttachType;
                  it["sParentCode"] = ite.sParentCode;
                  it["parentType"] = ite.sAttachType;
                  it["attachCode"] = ite.sAttachCode;
                  it["subNodeL"] = ite.fileList.length;
                  it["sType"] = "";
                  it["editStatus"] = "0";
                  it["fileName"] = "";
                  it["fileType"] = "";
                  that.historyGMDataList.push(it);
                })
                ite.fileList[0]["sType"] = ite.sAttachType;
              });
              break;
          }
        })
        setTimeout(() => {
          that.activeFileTab();
        }, 200)
      }
    })
  }

  // 产品树文件分类新增对象
  addSubTreeItem(item, type) {
    let that = this;
    let index: any;
    this.activeFileType = item.sParentCode;
    let newItem: any = {
      sType: item.sType,              // 小分类名称
      subNodeL: item.subNodeL + 1,    // 长度+1
      attachCode: item.attachCode,    // 小分类编码
      parentType: item.parentType,    // 小分类名称
      sParentType: item.sParentType,  // 大分类名称
      sParentCode: item.sParentCode,  // 大分类编码
      sAttachParentType: "",
      nAttachNo: "",
      sAttachType: item.parentType,   // 小分类名称
      sAttachCode: item.attachCode,   // 小分类编码
      sLinkFundnos: null,
      sAttachName: null,
      sLinkPrincipalNo: null,
      sLinkPrincipal: null,
      sStatus: null,
      dCreateTime: null,
      sCreator: null,
      sCreatorNo: null,
      nVersion: null,
      sAttachParentCode: null,
      sPath: null,
      nLastAttachNo: null,
      sFundType: item.sFundType,
      editStatus: "0",
      fileName: "",
      fileType: ""
    }
    switch (type) {
      case 'jcwjGM':
        index = _.indexOf(this.jcwjGMDataList, item);
        this.jcwjGMDataList[index].sType = "";
        this.jcwjGMDataList.splice(index, 0, newItem);
        break;
      case 'spwjGM':
        index = _.indexOf(this.spwjGMDataList, item);
        this.spwjGMDataList[index].sType = "";
        this.spwjGMDataList.splice(index, 0, newItem);
        break;
      case 'cpgzGM':
        index = _.indexOf(this.cpgzGMDataList, item);
        this.cpgzGMDataList[index].sType = "";
        this.cpgzGMDataList.splice(index, 0, newItem);
        break;
      case 'qtwjGM':
        index = _.indexOf(this.qtwjGMDataList, item);
        this.qtwjGMDataList[index].sType = "";
        this.qtwjGMDataList.splice(index, 0, newItem);
        break;
      case 'historyGM':
        index = _.indexOf(this.historyGMDataList, item);
        this.historyGMDataList[index].sType = "";
        this.historyGMDataList.splice(index, 0, newItem);
        break;
    }
  }

  // 显示上传文件框
  showUploadModal(item) {
    if (this.bgzcFileStatus == 1) {
      this.activeFileType = item.sParentCode;
      this.sAttachCode = item.attachCode;
      this.sAttachType = item.parentType;
      this.parentCode = item.sParentCode;
      this.parentType = item.sParentType;
      this.sFundType = item.sFundType;
      this.sCreator = sessionStorage.getItem('username');
      this.sCreatorNo = sessionStorage.getItem('username');
      if (item.nAttachNo == null) {
        this.nAttachNo = "";
      } else {
        this.nAttachNo = item.nAttachNo;
      }
      window['$']('#uploadModel').modal('show');
    } else if (this.bgzcFileStatus == 0) {
      window["swal"]("注意", "产品变更后才能进行上传文件!", "warning");
    }
  }

  // 获取上传文件的名称
  selectedFileOnChanged(event: any) {
    this.uploadFileName = event.target.value;
    this.fileStatus = true;
  }
  // 上传文件
  uploadFile() {
    let that = this;
    let reg = /[\#&*|/:"<>?]/gi;
    if (reg.test(_.last(this.uploader.queue).file.name)) {
      window["swal"]("提示", "文件名含有特殊字符!", "warning");
    } else {
      let fileItem = _.last(this.uploader.queue);
      fileItem.url = environment.server + '/pms/v1/common/fundFile/file?token=' + sessionStorage.getItem('token');
      fileItem.method = "POST";
      // 关联input框的“name”属性
      fileItem.alias = "file";
      fileItem.formData = [
        { key: "fileName", value: _.last(this.uploader.queue).file.name },
        { key: "nFundNo", value: this.nFileFundNo },
        { key: "nAttachNo", value: this.nAttachNo },
        { key: "sAttachCode", value: this.sAttachCode },
        { key: "sAttachType", value: this.sAttachType },
        { key: "parentCode", value: this.parentCode },
        { key: "parentType", value: this.parentType },
        { key: "sFundType", value: this.sFundType },
        { key: "sCreator", value: this.sCreator },
        { key: "sCreatorNo", value: this.sCreatorNo }
      ],
        // 添加 POST 其他参数
        this.uploader.onBuildItemForm = (item, form) => {
          _.forEach(fileItem.formData, item => {
            form.append(item.key, item.value);
          });
        };
      window['swal']({
        title: "提示",
        text: "是否确定上传 " + _.last(this.uploader.queue).file.name + " 附件?",
        type: "warning",
        showCancelButton: true,
        closeOnConfirm: false,
        confirmButtonText: "确认",
        confirmButtonColor: "#DD6B55",
        cancelButtonText: "取消",
        showLoaderOnConfirm: true,
      }, function (isConfirm) {
        if (isConfirm) {
          // 开始上传
          fileItem.upload();
          // 上传一个文件成功的回调
          fileItem.onSuccess = function (response, status, headers) {
            let resVal = JSON.parse(response);
            if (resVal.msg == "成功") {
              window["swal"]("成功", "文件上传成功!", "success");
              that.clearFileQueue();
              that.loadFileTree();
            } else {
              window["swal"](resVal.msg, resVal.detailMsg, "error");
              that.clearFileQueue();
            }
          }
        }
      })
    }
  }

  // 清除FileUploader上传队列中的所有文件
  clearFileQueue() {
    this.uploader.clearQueue();
    this.fileStatus = false;
    window['$']('#fileInput').val("");
    window['$']('#uploadModel').modal('toggle')
  }

  // 下载附件
  downLoadFile(item) {
    if (item.nAttachNo) {
      Util.attachDownload([item.nAttachNo]);
    } else {
      window['swal']("提示", "暂无文件下载", "warning");
    }
  }

  // 查看历史文件
  showHistoryVersion(item) {
    let that = this;
    this.activeFileType = item.sParentCode;
    this.fundInfoChangeService.getFileHistory(item.nAttachNo).subscribe(data => {
      if (data) {
        that.fileHistoryData = data;
        window['$']("#GM").modal('show');
      } else {
        window['swal']("提示", "暂无文件", "warning");
      }
    })
  }
  //关闭模态框
  closeModal() {
    window['$']("#GM").modal('hide');
  }
  // 删除文件
  delFile(item) {
    let that = this;
    window["swal"]({
      title: "注意",
      text: "是否确定删除 " + item.sAttachName + " 附件？",
      type: "warning",
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      showCancelButton: true,
      closeOnConfirm: false,
      closeOnCancel: true,
      showLoaderOnConfirm: true
    }, function (isConfirm) {
      if (isConfirm) {
        that.fundInfoChangeService.delFile(item.nAttachNo).subscribe(data => {
          if (data) {
            window['$']("#GM").modal('hide');
            window['swal']("成功", "文件已删除！", "success");
            window['$']("#detail-his-list-modal").modal('hide');
            that.loadFileTree();
          } else {
            window['swal']("失败", data.msg, "error");
          }
        })
      }
    })
  }
  // 编辑附件名称
  editFileName(item, type) {
    let that = this;
    this.activeFileType = item.sParentCode;
    // 该附件全名长度
    let len = item.sAttachName.length;
    // 该附件名最后一个.的位置
    let lastDotIndex = item.sAttachName.lastIndexOf(".");
    let index: any;
    switch (type) {
      case 'jcwjGM':
        // 该附件所在列表位置
        index = _.indexOf(this.jcwjGMDataList, item);
        // 获取附件文件名并赋值
        this.jcwjGMDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        // 获取附件扩展名并赋值
        this.jcwjGMDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.jcwjGMDataList[index].editStatus = "1";
        break;
      case 'spwjGM':
        index = _.indexOf(this.spwjGMDataList, item);
        this.spwjGMDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.spwjGMDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.spwjGMDataList[index].editStatus = "1";
        break;
      case 'cpgzGM':
        index = _.indexOf(this.cpgzGMDataList, item);
        this.cpgzGMDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.cpgzGMDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.cpgzGMDataList[index].editStatus = "1";
        break;
      case 'qtwjGM':
        index = _.indexOf(this.qtwjGMDataList, item);
        this.qtwjGMDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.qtwjGMDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.qtwjGMDataList[index].editStatus = "1";
        break;
      case 'historyGM':
        index = _.indexOf(this.historyGMDataList, item);
        this.historyGMDataList[index].fileName = item.sAttachName.substring(0, lastDotIndex);
        this.historyGMDataList[index].fileType = item.sAttachName.substring(lastDotIndex, len + 1);
        this.historyGMDataList[index].editStatus = "1";
        break;
    }
  }
  // 修改附件名
  changeFileName(item) {
    let that = this;
    // 去掉附件名首尾空格
    let filename = _.trim(item.fileName);
    if (filename !== "" && filename !== null) {
      let reg = /[\#&*|/:"<>?]/gi;
      if (reg.test(filename)) {
        window["swal"]("提示", "文件名含有特殊字符!", "warning");
      } else {
        let newFileName = encodeURI(filename) + item.fileType;
        window['swal']({
          title: "提示",
          text: "附件名称是否确定修改为 " + filename + " ?",
          type: "warning",
          showCancelButton: true,
          closeOnConfirm: false,
          confirmButtonText: "确认",
          confirmButtonColor: "#DD6B55",
          cancelButtonText: "取消",
          showLoaderOnConfirm: true,
        }, function (isConfirm) {
          if (isConfirm) {
            that.fundInfoChangeService.changeFileName(item.nAttachNo, newFileName).subscribe(data => {
              if (data) {
                window['swal']("成功", "附件名修改成功!", "success");
                that.loadFileTree();
              }
            })
          }
        })
      }
    } else {
      window['swal']("注意", "附件名不能为空", "warning")
    }
  }
  // 取消编辑附件名
  cancelEditFileName(item, type) {
    let index;
    switch (type) {
      case "jcwjGM":
        index = _.indexOf(this.jcwjGMDataList, item);
        this.jcwjGMDataList[index].editStatus = "0";
        break;
      case "spwjGM":
        index = _.indexOf(this.spwjGMDataList, item);
        this.spwjGMDataList[index].editStatus = "0";
        break;
      case "cpgzGM":
        index = _.indexOf(this.cpgzGMDataList, item);
        this.cpgzGMDataList[index].editStatus = "0";
        break;
      case "qtwjGM":
        index = _.indexOf(this.qtwjGMDataList, item);
        this.qtwjGMDataList[index].editStatus = "0";
        break;
      case "historyGM":
        index = _.indexOf(this.historyGMDataList, item);
        this.historyGMDataList[index].editStatus = "0";
        break;
    }
  }

  /**
   * 计算延期回函到期日为延期募集批复时间+6个月
   * @param
   */
  calculateDraisePostponeHh($event) {
    setTimeout(() => {
      if (this.yqmjPostBody.publicissueExamineInfo.dRaisePostponePf !== '' && this.yqmjPostBody.publicissueExamineInfo.dRaisePostponePf !== null) {
        var date = moment(this.yqmjPostBody.publicissueExamineInfo.dRaisePostponePf).add('months', 6).format('YYYY/MM/DD');
        this.yqmjPostBody.publicissueExamineInfo.dRaisePostponeHh = moment(date).format('YYYY-MM-DD');
      }

    }, 200);
  }

  /**
   *  选择非上市产品，清空交易市场
   */
  changeExchangeStatus() {
    if (this.bgzcInfo.publicissueBasicInfo.sListType == "0") {
      this.bgzcInfo.publicissueBasicInfo.sExchange = "";
    }
  }

  // 切换tab清空附件类型
  clearFileType() {
    this.activeFileType = "";
  }
  // 激活文件tab
  activeFileTab() {
    let that = this;
    window['$']('#tab4').removeClass('active');
    window['$']('#tab_4').removeClass('active');
    window['$']('#tab18').removeClass('active');
    window['$']('#tab_18').removeClass('active');
    window['$']('#tab22').removeClass('active');
    window['$']('#tab_22').removeClass('active');
    window['$']("#jcwjGMContent").attr('aria-expanded', "false");
    window['$']('#tab5').removeClass('active');
    window['$']('#tab_5').removeClass('active');
    window['$']('#tab19').removeClass('active');
    window['$']('#tab_19').removeClass('active');
    window['$']('#tab23').removeClass('active');
    window['$']('#tab_23').removeClass('active');
    window['$']("#spwjGMContent").attr('aria-expanded', "false");
    window['$']('#tab6').removeClass('active');
    window['$']('#tab_6').removeClass('active');
    window['$']('#tab20').removeClass('active');
    window['$']('#tab_20').removeClass('active');
    window['$']('#tab24').removeClass('active');
    window['$']('#tab_24').removeClass('active');
    window['$']("#cpgzwjGMContent").attr('aria-expanded', "false");
    window['$']('#tab7').removeClass('active');
    window['$']('#tab_7').removeClass('active');
    window['$']('#tab21').removeClass('active');
    window['$']('#tab_21').removeClass('active');
    window['$']('#tab25').removeClass('active');
    window['$']('#tab_25').removeClass('active');
    window['$']("#qtwjGMContent").attr('aria-expanded', "false");
    window['$']('#tab8').removeClass('active');
    window['$']('#tab_8').removeClass('active');
    window['$']('#tab17').removeClass('active');
    window['$']('#tab_17').removeClass('active');
    window['$']('#tab30').removeClass('active');
    window['$']('#tab_30').removeClass('active');
    window['$']("#historyGMContent").attr('aria-expanded', "false");
    if (this.activeFileType == "") {
      this.activeFileType = this.activeFileList[0];
    }
    switch (this.activeFileType) {
      case "jcwjGM":
        window['$']('#tab4').addClass('active');
        window['$']('#tab_4').addClass('active');
        window['$']('#tab18').addClass('active');
        window['$']('#tab_18').addClass('active');
        window['$']('#tab22').addClass('active');
        window['$']('#tab_22').addClass('active');
        window['$']("#jcwjGMContent").attr('aria-expanded', "true");
        break;
      case "spwjGM":
        window['$']('#tab5').addClass('active');
        window['$']('#tab_5').addClass('active');
        window['$']('#tab19').addClass('active');
        window['$']('#tab_19').addClass('active');
        window['$']('#tab23').addClass('active');
        window['$']('#tab_23').addClass('active');
        window['$']("#spwjGMContent").attr('aria-expanded', "true");
        break;
      case "cpgzwjGM":
        window['$']('#tab6').addClass('active');
        window['$']('#tab_6').addClass('active');
        window['$']('#tab20').addClass('active');
        window['$']('#tab_20').addClass('active');
        window['$']('#tab24').addClass('active');
        window['$']('#tab_24').addClass('active');
        window['$']("#cpgzwjGMContent").attr('aria-expanded', "true");
        break;
      case "qtwjGM":
        window['$']('#tab7').addClass('active');
        window['$']('#tab_7').addClass('active');
        window['$']('#tab21').addClass('active');
        window['$']('#tab_21').addClass('active');
        window['$']('#tab25').addClass('active');
        window['$']('#tab_25').addClass('active');
        window['$']("#qtwjGMContent").attr('aria-expanded', "true");
        break;
      case "historyGM":
        window['$']('#tab8').addClass('active');
        window['$']('#tab_8').addClass('active');
        window['$']('#tab17').addClass('active');
        window['$']('#tab_17').addClass('active');
        window['$']('#tab30').addClass('active');
        window['$']('#tab_30').addClass('active');
        window['$']("#historyGMContent").attr('aria-expanded', "true");
        break;
    }
  }

  /**
 * 判断发行日期是否比成立日期早
 */
  beforeTime() {
    if (this.bgzcInfo.publicissueBasicInfo.dIssue !== "" && this.bgzcInfo.publicissueBasicInfo.dIssue !== null && this.bgzcInfo.publicissueBasicInfo.dEstablishment !== "" && this.bgzcInfo.publicissueBasicInfo.dEstablishment !== null) {
      if (this.bgzcInfo.publicissueBasicInfo.dIssue == this.bgzcInfo.publicissueBasicInfo.dEstablishment) {
        return true;
      } else {
        if (moment(this.bgzcInfo.publicissueBasicInfo.dEstablishment).isBefore(this.bgzcInfo.publicissueBasicInfo.dIssue)) {
          return true;
        } else {
          return false;
        }
      }
    } else {
      return true;
    }
  }
  // 新增必填校验
  requireAdd() {
    let that = this;
    let requiredAddTips = [];
    let sFundName = _.trim(this.bgzcInfo.publicissueBasicInfo.sFundName);
    let sPmAccount = _.trim(this.bgzcInfo.publicissueBasicInfo.sPmAccount);
    let sInvestStyle = _.trim(this.bgzcInfo.publicissueBasicInfo.sInvestStyle);
    if (sFundName == "" || sFundName == null) {
      requiredAddTips.push("产品简称");
    }
    if (this.bgzcInfo.publicissueBasicInfo.sFundCategory == "" || this.bgzcInfo.publicissueBasicInfo.sFundCategory == null) {
      requiredAddTips.push("基金类别");
    }
    if (this.bgzcInfo.publicissueBasicInfo.sIsQdii == "" || this.bgzcInfo.publicissueBasicInfo.sIsQdii == null) {
      requiredAddTips.push("QDII");
    }
    if (sInvestStyle == "" || sInvestStyle == null) {
      requiredAddTips.push("基金运作方式");
    }
    if (sPmAccount == "" || sPmAccount == null) {
      requiredAddTips.push("基金经理");
    }
    if (this.bgzcInfo.publicissueBasicInfo.sListType == "" || this.bgzcInfo.publicissueBasicInfo.sListType == null) {
      requiredAddTips.push("是否上市基金");
    }
    if (this.bgzcInfo.publicissueBasicInfo.sListType == "1") {
      if (this.bgzcInfo.publicissueBasicInfo.sExchange == "" || this.bgzcInfo.publicissueBasicInfo.sExchange == null) {
        requiredAddTips.push("交易所");
      }
    }
    if (requiredAddTips.length > 0) {
      let sRequiredAddTips = requiredAddTips.join("、");
      window['swal']("提示", "请填写:" + sRequiredAddTips, "warning");
      return false;
    } else {
      return true;
    }
  }
  // 基金经理
  getManagerList() {
    let that = this;
    this.fundInfoChangeService.getManagerList().subscribe(data => {
      that.managerList = data;
    })
  }
  // 多选下拉框基金经理
  ctrlManagerId() {
    let managerIdList: any;
    let managerChecked = [];
    let selected = window['$']('.fields-select').val();
    _.forEach(selected, item => {
      let index1 = item.indexOf("'");
      let index2 = item.lastIndexOf("'");
      let manager = item.substring(index1 + 1, index2);
      managerChecked.push(manager);
    })
    managerIdList = managerChecked.join(",");
    return managerIdList;
  }
  // 多选下拉框基金经理Name
  ctrlManagerName() {
    let that = this;
    let managerNameList: any;
    let managerChecked = [];
    let managerId = this.ctrlManagerId().split(",");
    _.forEach(managerId, item => {
      _.forEach(that.managerList, it => {
        if (item == it.sUserName) {
          managerChecked.push(it.sRealName);
        }
      })
    })
    managerNameList = managerChecked.join(",");
    return managerNameList;
  }
  //计算字符串字符长度
  mathStringLength(item) {
    this.realLength = Util.mathStringLength(item)
  }
  // ngAfterViewInit() {
  //   let that = this;
  //   // 托管人
  //   window['$']('#sTrusteeSelected').select2({ width: '184px', tags: true });
  //   window['$']('#sTrusteeSelected').on("select2:select", function (e) {
  //     that.bgzcInfo.publicissueBasicInfo.sBank = window['$']('#sTrusteeSelected').select2("val");
  //   })
  // }
  // 获取备案机构、受托人、托管人下拉框值
  getDictionary() {
    let that = this;
    this.fundInfoChangeService.getDictionary().subscribe(data => {
      if (data) {
        
        that.distionary.RECORDORG_TYPE = data.RECORDORG_TYPE;
        that.distionary.LINK_PRINCIPAL_NO = data.LINK_PRINCIPAL_NO;
        that.distionary.TRUSTEE = data.TRUSTEE;
        that.distionary.INVEST_STYLE = data.INVEST_STYLE;
        console.log(that.distionary.TRUSTEE);
      }
    })
  }
}
